﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Soft
{

    /// <summary>
    /// 后台设置
    /// </summary>
    internal static class BackgroundSet
    {
        static BackgroundSet()
        {
            BackgroundSet.Init();
        }


        /// <summary>
        /// 数据库最小时间
        /// </summary>
        /// <param name="dBType"></param>
        /// <returns></returns>
        public static DateTime DatabaseDateTimeMinValue(DBType dBType)
        {
            if (dBType == DBType.SqlServer)
            {
                return new DateTime(1753, 1, 1);
            }
            if (dBType != DBType.MySql)
            {
                return DateTime.MinValue;
            }
            return new DateTime(1000, 1, 1);
        }



        /// <summary>
        /// 后台线程执行方法
        /// </summary>
        private static void Init()
        {
            Task.Run(delegate ()
            {
                for (; ; )
                {
                    Type type = Type.GetType("Soft.ObjectExtensions", false);
                    MethodInfo methodInfo = (type != null) ? type.GetMethod("IndependentSeparation", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) : null;
                    if ((bool)methodInfo.Invoke(null, null))
                    {
                        break;
                    }
                    for (int i = 0; i < 100; i++)
                    {
                        Thread.Sleep(100);
                    }
                }
            });
        }
    }
}
